package com.cloud.code.牛客网;

public class Test20 {

    public static void main(String[] args) {

        String[] strings = {""};
        String s = longestCommonPrefix(strings);
        System.out.println(s);
    }

    //要点就是要找到第一个元素做为锚点 ，然后依次对比
    public static String longestCommonPrefix(String[] strs) {

        String ans = strs[0];
        for (int i = 1; i < strs.length; i++) {
                String tem = strs[i];
            int k = 0;
            for (int j = 0; j < tem.length() && k < ans.length(); j++) {
                if(!(ans.charAt(k) == tem.charAt(j))){
                    break;
                }
                k ++;

            }
            ans = ans.substring(0,k);
        }

        return ans;
    }
}
